package algorithms.que13;

import edu.princeton.cs.algs4.Queue;
import edu.princeton.cs.algs4.StdOut;

import java.io.File;

/**
 * @功能
 * @创建时间 2020/8/1
 */
public class ShowFile {
    private class MyFile
    {
        String name;
        int level;
    }
    public static void main(String[] args)
    {
        String dirName=args[0];
        File f=new File(dirName);
        Queue<MyFile> q=new Queue<MyFile>();
        int level=0;
        ShowFile mytest=new ShowFile();
        mytest.ShowAllDirAndFile(f,q,level);
        for(MyFile i:q)
            StdOut.printf("%"+3*i.level+"s%s\n","",i.name);
    }//end main

    public  void ShowAllDirAndFile(File f,Queue<MyFile> q,int level)
    {
        if(f==null) return;
        level++;
        if(f.isDirectory())
        {
            MyFile myfile=new MyFile();
            myfile.name=f.getName().toString();
            myfile.level=level;
            q.enqueue(myfile);
            File[] files=f.listFiles();
            if(files.length>0)
                for(File file:files)
                    ShowAllDirAndFile(file,q,level);
        }
        else
        {
            MyFile myfile=new MyFile();
            myfile.name=f.getName().toString();
            myfile.level=level;
            q.enqueue(myfile);
        }
    }
}
